package top.ivansong.tool.json;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;

/**
 * TODO
 */
@Slf4j
public class FastJsonUtil {
    private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();

    /**
     * 解析Json字符串
     *
     * @param str   Json字符串
     * @param clazz 反序列化的类
     * @return 实体
     */
    public static <T> T parseObject(String str, Class<T> clazz) {
        try {
            return OBJECT_MAPPER.readValue(str, clazz);
        } catch (JsonProcessingException e) {
            log.error("parse object error, str:{}, clazz:{}", str, clazz, e);
            return null;
        }
    }
}
